<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.1.2/echarts.min.js"></script>
  <title>图表自适应</title>
</head>

<body>
  <div style="height: 400px;"></div>
  <script>
    var mChart = echarts.init(document.querySelector('div'));
    var xDataArr = ['张三', '李四', '王五', '小明', '小红', '小张'];
    var yDataArr = [100, 40, 80, 26, 88, 70];
    var option = {
      xAxis: {
        type: 'category',
        data: xDataArr
      },
      yAxis: {
        type: 'value'
      },
      series: [{
        name: '语文',
        type: 'bar',
        data: yDataArr,
        barWidth: 30
      }]
    };
    mChart.setOption(option);
    window.onresize = function() {
      mChart.resize();
    }
  </script>
</body>

</html>